package com.bjx.flow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.flow.domain.query.FlowGroupQuery;
import com.bjx.flow.domain.vo.FlowGroupVO;
import com.bjx.flow.service.IFlowGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 流程分组控制器
 * @author: liushuai
 * @date: 2022/10/24
 */
@RequestMapping("/group")
@Tag(name = "流程分组控制器")
@RestController
public class FlowGroupController {

    @Autowired
    private IFlowGroupService flowGroupService;

    /**
     * 分页查询流程分组列表
     * @param flowGroupQuery
     * @return: R<IPage<FlowGroupVO>>
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "分页查询流程分组列表")
    @GetMapping("listFlowGroupPage")
    public R<IPage<FlowGroupVO>> listFlowGroupPage(FlowGroupQuery flowGroupQuery) {
        IPage<FlowGroupVO> page = flowGroupService.listFlowGroupPage(flowGroupQuery);
        return R.success(page);
    }

    /**
     * 获取所有流程分组
     * @param
     * @return: com.bjx.common.core.domain.R<java.util.List<com.bjx.flow.domain.vo.FlowGroupVO>>
     * @Author: liushuai
     * @Date: 2022/10/25 10:01
     */
    @Operation(summary = "获取所有流程分组")
    @GetMapping("listFlowGroupAll")
    public R<List<FlowGroupVO>> listFlowGroupAll() {
        List<FlowGroupVO> list = flowGroupService.listFlowGroupAll();
        return R.success(list);
    }

    /**
     * 根据流程分组id查询流程分组
     * @param groupId
     * @return:R<FlowGroupVO>
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "根据流程分组id查询流程分组")
    @GetMapping("selectFlowGroupByGroupId")
    public R<FlowGroupVO> selectFlowGroupByGroupId(@RequestParam Long groupId){
        FlowGroupVO vo = flowGroupService.selectFlowGroupByGroupId(groupId);
        return R.success(vo);
    }

    /**
     * 根据流程分组id删除流程分组
     * @param groupId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "根据流程分组id删除流程分组")
    @GetMapping("deleteFlowGroupByGroupId")
    public R deleteFlowGroupByGroupId(@RequestParam Long groupId){
        flowGroupService.deleteFlowGroupByGroupId(groupId);
        return R.successMsg("删除流程分组成功");
    }

   /**
    * 新增流程分组
    * @param flowGroupVO
    * @return: R
    * @Author: liushuai
    * @Date: 2022/10/24
    */
   @Operation(summary = "新增流程分组")
   @PostMapping("insertFlowGroup")
   public R insertFlowGroup(@RequestBody @Validated FlowGroupVO flowGroupVO){
      flowGroupService.insertFlowGroup(flowGroupVO);
      return R.successMsg("新增流程分组成功");
   }

    /**
     * 修改流程分组
     * @param flowGroupVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "修改流程分组")
    @PostMapping("updateFlowGroup")
    public R updateFlowGroup(@RequestBody @Validated(Update.class) FlowGroupVO flowGroupVO){
        flowGroupService.updateFlowGroup(flowGroupVO);
        return R.successMsg("修改流程分组成功");
    }
}
